
package car;

import javax.swing.*;
import java.awt.*;

public class CarDashboard extends JPanel{
    private int speed = 0;
    private int rpm = 0;
    private int temperature = 0;
    private int fuelConsumption = 0;

    public int getRpm() {
        return rpm;
    }

    public void setRpm(int rpm) {
        this.rpm = rpm;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getTemperature() {
        return temperature;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public int getFuelConsumption() {
        return fuelConsumption;
    }

    public void setFuelConsumption(int fuelConsumption) {
        this.fuelConsumption = fuelConsumption;
    }

    public CarDashboard() {
        JFrame frame = new JFrame("汽车仪表盘");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 700);
        frame.setLocationRelativeTo(null);
        frame.add(this);
        frame.setVisible(true);
    }
    private void updateValues() {
        rpm = (rpm + 50) % 8000;
        speed = (rpm / 100) % 240;
        fuelConsumption = (rpm / 100) % 100;
        temperature = (rpm / 100) % 100;
    }
    public  void run() {
        Timer timer = new Timer(200,e ->  {
            updateValues();
            repaint();
        });
        timer.start();
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        CirclePanel.drawCirclePanel(g2, 250, 30, 500, 500, 240, speed, 180, -180, 20, "%d");

        RingPanel.drawRingPanel(g2, 350, 350, 250, 250, 8000, rpm, Color.RED);

        LinePanel.drawLinePanel(g2, 50, 350, 250, 250, 100, temperature, Color.RED);

        LinePanel.drawLinePanel(g2, 650, 350, 250, 250, 100, fuelConsumption, Color.BLUE);

        TextPanel.drawTextPanel(g2,"Speed: " + speed + " km/h",480,200);
        TextPanel.drawTextPanel(g2,"RPM: " + rpm + " rpm",475,500);
        TextPanel.drawTextPanel(g2,"Temp: " + temperature + " °C",175,630);
        TextPanel.drawTextPanel(g2,"Fuel: " + fuelConsumption + " L/100km",775,630);
    }
    public static void main(String[] args) {
        CarDashboard carDashboard = new CarDashboard();
        carDashboard.run();
    }
}


/*package car;

import javax.swing.*;

public class CarDashboard {
    DrawGauge drawGauge = new DrawGauge();

    public CarDashboard(){
        JFrame frame = new JFrame("汽车仪表盘");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 700);
        frame.setLocationRelativeTo(null);
        frame.add(drawGauge);
        frame.setVisible(true);
    }
    public void run(){
        Timer timer = new Timer(200, e -> {
            drawGauge.updateValues();
            drawGauge.repaint();
        });
        timer.start();

    }
    public static void main(String[] args) {
        CarDashboard dashboard = new CarDashboard();
        dashboard.run();
    }
}*/
